package wg

/*
// +build ignore
// 编译参数
#cgo CFLAGS: -Iwincompat/include -include wincompat/compat.h -DWINVER=0x0601 -D_WIN32_WINNT=0x0601 -flto   
// 链接参数
#cgo LDFLAGS: ./wg/libwg.a -lws2_32 -lsetupapi -lole32 -ladvapi32 -lntdll -Lwincompat  

#include <stdlib.h>
#include <subcommands.h>
#include <containers.h>
#include <ipc.h>
*/
import "C"

import (
	//"unsafe"
	//"os"
	//"github.com/labstack/gommon/log"
	//"fmt"
	//"errors"
)

func main__() {
	//cStr := C.CString("hello world !") // golang 操作c 标准库中的CString函数
	//C.print_fun1(cStr)                 // 调用C函数：print_fun 打印输出
	// 创建一个 C 数组来存储命令行参数
	/*
	args := os.Args
	argv := make([]*C.char, len(args))
	for i, arg := range args {
		argv[i] = C.CString(arg)
		defer C.free(unsafe.Pointer(argv[i]))
	}

	// 将 C 数组传递给 C 函数
	C.set_main(C.int(len(argv)), &argv[0])
	*/
	//defer C.free(unsafe.Pointer(cStr)) // 因为 CSstring 这个函数没有对变量申请的空间进行内存释放
}
/*
//windows 上实现wg 指令
func run_windows_set(args ...string) (string, error) {
	log.Info(args)
	//b, err := exec.Command( args...).Output()
	argv := make([]*C.char, len(args))
	defer func() {
		for _, arg := range argv {
			C.free(unsafe.Pointer(arg))
		}
	}()
	for i, arg := range args {
		argv[i] = C.CString(arg)
	}
	C.set_main(C.int(len(argv)), &argv[0])
	return "", nil
	
	//return strings.TrimSpace(string(b)), nil
}

func run_windows(args ...string)(string, error) {
	argv := make([]*C.char, len(args))
	for i, arg := range args {
		argv[i] = C.CString(arg)
		defer C.free(unsafe.Pointer(argv[i]))
	}
	C.main1(C.int(len(argv)), &argv[0])
	return "", nil
}

func getDevice_peer(interfaceName string) (*C.struct_wgdevice, error) {
	var dev *C.struct_wgdevice
	//struct wgpeer *peer;
	var peer *C.struct_wgpeer
	if ret := C.ipc_get_device(&dev, C.CString(interfaceName)); ret < 0 {
		errMsg := fmt.Sprintf("Unable to access interface %s: %s", interfaceName, C.GoString(C.strerror(C.int(ret))))
		return nil, errors.New(errMsg)
	}
	//for_each_wgpeer
	for peer = dev.first_peer; peer != nil; peer = peer.next_peer {
		
	}
	C.free_wgdevice(dev)
	return dev, nil
}
*/